package com.baseframe.blog.controller;

import com.baseframe.auth.utils.AuthUtil;
import com.baseframe.blog.entity.SnsBlogComment;
import com.baseframe.blog.entity.request.SnsBlogCommentRequest;
import com.baseframe.blog.service.SnsBlogCommentService;
import com.baseframe.tool.result.R;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/front/blog/comment")
@AllArgsConstructor
public class FrontSnsCommentController {

    private SnsBlogCommentService snsBlogCommentService;

    @PostMapping("/add")
    public R<Object> addComment(@RequestBody SnsBlogCommentRequest request){

        if(request.getBlogId()==null){
            return R.fail("评论发表失败:缺少必要请求参数~");
        }

        SnsBlogComment snsBlogComment = new SnsBlogComment();

        BeanUtils.copyProperties(request,snsBlogComment);

        snsBlogComment.setUserId(AuthUtil.getUserId());

        return snsBlogCommentService.save(snsBlogComment)?R.success():R.fail();

    }

    @GetMapping("/list")
    public R<Object> getBlogCommentList(SnsBlogCommentRequest request){

        if(request.getBlogId() == null){
            return R.fail("获取评论列表失败:缺少必要请求参数~");
        }

        return R.data(snsBlogCommentService.getCommentAllInfoList(request));
    }



}
